import traceback
import requests


# 紫东太初
class TaiChu:
    # app_key
    api_key = 'xaeb04bclq5vk90i1p2xeb9b'

    def __init__(self, model_code="taichu_llm"):
        """
            初始化参数
        :param model_code: 模型类型
        """
        self.params = {'api_key': self.api_key, 'model_code': model_code, 'do_stream': False}

    # 获取文本内容
    def send_text_message(self, question):
        self.params["question"] = question
        try:
            # 请求参数
            url = "https://ai-maas.wair.ac.cn/maas/v1/model_api/invoke"
            print("紫东太初 获取文本内容", url, self.params)
            response = requests.post(url, json=self.params)
            print("紫东太初 返回内容", response.text)
            if response.status_code == 200:
                result = response.json()
                return True, result["data"]["content"]
            else:
                return False, response.text
        except Exception:
            print("紫东太初 获取文本内容异常", traceback.format_exc())
            return False, "请求接口异常"